/*
 * 
 * Copyright (C) 2010 Wilfried Elmenreich, Anita Sobe 
 * This file is part of VideoNetwork.
 * 
 * VideoNetwork is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. 
 */
package proxy;

import java.util.ArrayList;


public class UnitContainer implements Comparable<UnitContainer> {

	private VideoUnit videoUnit;

	/**
	 * For units in incomingUnits this means they have arrived 
	 * and may be transferred to storedUnits.
	 */
	
	public double viewedUntil;
	public double copyProcessUntil;
	private boolean deleteAfterCopy=false;
	
	ServerNode source, destination;
	/**
	 * higher priority (larger number) will be processed first when unit is transmitted over a link 
	 */
	double priority;
	
	ArrayList<ServerNode> route;
	
	public double lastUse() {
		if (viewedUntil > copyProcessUntil)
			return viewedUntil;
		return copyProcessUntil;
	}
	
	public UnitContainer(VideoUnit videoUnit) {
		this.videoUnit=videoUnit;
		copyProcessUntil=0.0;
		viewedUntil=0.0;
		route=null;
	}
	
	public UnitContainer(VideoUnit videoUnit,double copyOperationUntil) {
		this.videoUnit=videoUnit;
		this.copyProcessUntil=copyOperationUntil;
		route=null;
	}

	public boolean isDeleteAfterCopy() {
		return deleteAfterCopy;
	}

	public void setDeleteAfterCopy(boolean deleteAfterCopy) {
		this.deleteAfterCopy = deleteAfterCopy;
	}

	public VideoUnit getVideoUnit() {
		return videoUnit;
	}

	public int compareTo(UnitContainer o) {
		if (o.lastUse() < lastUse()) return -1;
		if (o.lastUse() > lastUse()) return 1;
		return 0;
	}		
}
